#include "hnsw.hpp"
#include "util/vecs_io.hpp"
#include "util/graph_io.hpp"
#include "util/enter_point.hpp"

using namespace std;
using namespace GraphGradient;

void
save(const char *base_path, const char *dataset_name) {
    const int M = 40;
    const int ef_construction = 100;
    const int random_seed = 100;
    const int n_index = 1;

    const int ef_search_config[3] = {10, 5, 10}; //start, stride, iter

    int n_query, top_k, n_base, data_dim;
    top_k = 10;

    vector<float *> data = read_data(dataset_name, n_query, top_k, n_base, data_dim);
    float *base = data[0];
    float *query = data[1];
    int *gnd = (int *) data[2];

    printf("dataset %s, M %d, efConstruction %d, n_index %d\n", dataset_name, M, ef_construction,
           n_index);

    //build index
    vector<int> indexing_time_l(n_index);
    TimeRecord total_insert_record;

    printf("building hnsw index\n");
    HNSW hnsw(data_dim, n_base, M, ef_construction, random_seed);
    hnsw.insert(base);
//    hnsw.test_graph();
    vector <vector<int>> graph = hnsw.get_bottom_graph();

    int enter_point = get_ep_centroid(graph, base, 100, data_dim);
    char path[256];
    sprintf(path, "%s/%s", base_path, dataset_name);
    save_graph(graph, base, data_dim, "hnsw", path, enter_point);
}

int main() {
    save("../data", "siftsmall");
    save("../data", "deep");
    save("../data", "gist");
    save("../data", "glove");
    save("../data", "sift");
    return 0;
}